#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
LL arr[200005];
LL check(unsigned x){
    LL ans=0;
    for (int i=1;i<=n;++i){
        if ((x>>(i-1))&1){
            for (int j=i-1;j;--j){
                if ((x>>(j-1))&1){ans+=(arr[j]==arr[i])?arr[i]:0;break;}
            }
        }else{
            for (int j=i-1;j;--j){
                if (!((x>>(j-1))&1)){ans+=(arr[j]==arr[i])?arr[i]:0;break;}
            }
        }
    }
    return ans;
}
void solve(){
    scanf("%d",&n);
    LL ans=0;
    for (int i=1;i<=n;++i){scanf("%lld",arr+i);}
    for (unsigned i=0;i<(1U<<n);++i){
        ans=max(ans,check(i));
    }
    printf("%lld\n",ans);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;scanf("%d",&T);++T;while (--T){solve();}
    return 0;
}
